<?php

namespace app\common\logic;

class Action extends LogicCore
{
	
    //重置/获取缓存
    public function _ResetCache($_Type = false){
		cache('sys.action', NULL);
        $_Data = $this->_Cache($_Type);
		if($_Type){
			return $_Data;
		}
	}
	
    //设置/获取缓存
    public function _Cache($_Type = false){
        //获取缓存中的模块列表
        $_Data = cache('sys.action');
        //判断缓存是否存在
        if(!$_Data){
            //从数据库中读取开启状态的模块
            $_Data = db('Action')->where(['status'=>1])->column('id,log','name');
            $_ActionPlugList = db('ActionPlug')->alias('ap')->where(['ap.status'=>1])->join('plug p','ap.plug_id = p.id')->field('ap.id,ap.plug_id,ap.action_id,ap.func,ap.setting,p.name')->order('ap.sort asc')->select();
			$_ActionPlug = [];
			foreach($_Data as $K => $V){
				foreach($_ActionPlugList as $K2 => $V2){
					if($V['id'] == $V2['action_id']){
						$_ActionPlug[$K][]=[
							'id'=>$V2['id'],
							'plug'=>$V2['name'],
							'func'=>$V2['func'],
							'setting'=>$V2['setting'],
						];
					}
				}
			}
            //将读取模块数据 进行缓存
            cache('sys.action',$_Data);
            //将读取模块数据 进行缓存
            cache('sys.action_plug',$_ActionPlug);
			cache('sys.action_plug_cache',null);
        }
		if($_Type){
			return $_Data;
		}
    }
}